package org.atlantis.datasink.cfg;

import java.util.HashMap;
import java.util.Map;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public abstract class AbstractOptionFragment<T extends Option> implements OptionFragment<T> {

	public static final String NAME_ATTR = "name";
	public static final String EXTENDS_TAG = "extends";
	public static final String EXTEND_TAG = "extend";
	public static final String EXTEND_ATTR_KEY = "key";

	protected Map<String, String> parseExtend(Element extendElm) {
		Map<String, String> extendOptions = new HashMap<String, String>();
		NodeList extendList = extendElm.getElementsByTagName(EXTEND_TAG);
		for (int i = 0; i < extendList.getLength(); i++) {
			Element extend = (Element) extendList.item(i);
			String key = extend.getAttribute(EXTEND_ATTR_KEY);
			String value = extend.getFirstChild().getNodeValue();
			extendOptions.put(key, value);
		}
		return extendOptions;
	}
}
